package com.appforged.AppForged;

import java.util.Random;

import com.appforged.AppForged1.R;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.InputType;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;

public class TextPlay extends Activity implements View.OnClickListener {

	Button chkCmd;
	ToggleButton pwTog;
	EditText input;
	TextView output;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.textplay);

		VarMethod();

		pwTog.setOnClickListener(this);
		chkCmd.setOnClickListener(this);
		
	}

	private void VarMethod() {
		chkCmd = (Button) findViewById(R.id.bResults);
		pwTog = (ToggleButton) findViewById(R.id.tbPassword);
		input = (EditText) findViewById(R.id.etCommands);
		output = (TextView) findViewById(R.id.tvResults);

	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		
		switch (v.getId()) {
		case R.id.bResults:
			String check = input.getText().toString();
			output.setText(check);
			if (check.contentEquals("left")) {
				output.setGravity(Gravity.LEFT);
				output.setText("left");

			} else if (check.contentEquals("right")) {
				output.setGravity(Gravity.RIGHT);
				output.setText("right");
				
			} else if (check.contentEquals("blue")) {
				output.setTextColor(Color.BLUE);
				output.setGravity(Gravity.CENTER);
				
			} else if (check.contains("WTF")) {
				Random crazy = new Random();
				output.setText("WTF!!!!");
				output.setTextSize(crazy.nextInt(75));
				output.setTextColor(Color.rgb(crazy.nextInt(255),
						crazy.nextInt(255), crazy.nextInt(255)));
				
				switch (crazy.nextInt(3)) {
				case 0:
					output.setGravity(Gravity.LEFT);
					break;

				case 1:
					output.setGravity(Gravity.RIGHT);
					break;

				case 2:
					output.setGravity(Gravity.CENTER);
					break;

				default:
					break;
				}

			} else {
				output.setGravity(Gravity.CENTER);
				output.setText("Nope, Friut loops PC");
				output.setTextColor(Color.WHITE);

			}
			break;
			
		case R.id.tbPassword:
			if (pwTog.isChecked()) {
				input.setInputType(InputType.TYPE_CLASS_TEXT
						| InputType.TYPE_TEXT_VARIATION_PASSWORD);

			} else {
				input.setInputType(InputType.TYPE_CLASS_TEXT);

			}
			break;

		}
	}

}
